package com.dhwl.hsh.driver.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.dhwl.hsh.driver.R;
import com.dhwl.hsh.driver.common.Constant;
import com.dhwl.hsh.driver.ui.adapter.TruckListAdapter;

import butterknife.Bind;

/**
 * 选择车型
 *
 * @author Derek.Kidd
 * @time 2016/4/26 18:32
 */
public class TruckListActivity extends BaseActivity {

    @Bind(R.id.list_truck)
    ListView listTruck;

    TruckListAdapter listAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_truck_list;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setTitleContent("选择车型");
        topbarLeftImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onComplete();
                finish();
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        onComplete();
    }

    @Override
    protected void initData() {
        listAdapter = new TruckListAdapter(this);
        listTruck.setAdapter(listAdapter);
        listAdapter.notifyDataSetChanged();
    }

    private void onComplete() {
        Intent intent = new Intent();
        intent.putExtra(Constant.Order.KEY_TRUCK_TYPE, listAdapter.getCheckNum());
        setResult(RESULT_OK, intent);
    }
}
